package com.example.tijianserver.controller;

import com.example.tijianserver.dto.OrdersMapperDto;
import com.example.tijianserver.dto.PersonalOrderDTO;
import com.example.tijianserver.dto.ReportListDTO;
import com.example.tijianserver.pojo.Hospital;
import com.example.tijianserver.pojo.Orders;
import com.example.tijianserver.pojo.Setmeal;
import com.example.tijianserver.pojo.Users;
import com.example.tijianserver.response.ApiRestResponse;
import com.example.tijianserver.service.HospitalService;
import com.example.tijianserver.service.OrdersService;
import com.example.tijianserver.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @Autowired
    HospitalService hospitalService;
    @Autowired
    SetmealService setmealService;

    @RequestMapping("/saveOrders")
    public ApiRestResponse listByType(@RequestBody Orders orders) {
       return ApiRestResponse.success(ordersService.insert(orders));
    }

    //   获取订单的套餐和医院信息
    @PostMapping("/getSmAndHp")
    public ApiRestResponse getSmAndHp(@RequestBody OrdersMapperDto ordersMapperDto){

        Map<String,Object> map=new HashMap<>();

        Setmeal setmeal=setmealService.selectByPrimaryKey(ordersMapperDto.getSmId());
        Hospital hospital=hospitalService.selectByPrimaryKey(ordersMapperDto.getHpId());

        map.put("setmeal",setmeal);
        map.put("hospital",hospital);

        return ApiRestResponse.success(map);
    }

//    获取个人体检预约信息
    @RequestMapping("/person")
    public List<PersonalOrderDTO> getPersonOrder(@RequestBody Users users) throws ParseException {
        return ordersService.getPOrder(users.getUserId());
    }

//取消订单 state：2=>4
    @RequestMapping("/cancel")
    public ApiRestResponse cancel(@RequestBody Orders orders){

//        System.out.println(orders.getOrderId());
        return ApiRestResponse.success(ordersService.updatestate(orders.getOrderId(),4));
    }


    //用户已完成订单列表
    @RequestMapping("/getReportList")
    public ApiRestResponse<List<ReportListDTO>> getReportList(@RequestBody Orders orders){
        return ApiRestResponse.success(ordersService.getReport(orders));

    }


}
